package com.smart.base.taskTest.selector;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.codehaus.groovy.reflection.stdclasses.CharacterCachedClass;
import org.h2.mvstore.WriteBuffer;

public class SocketClients implements Runnable{
	
		
		@Override
		public void run() {
			Socket socket =null;
			OutputStream outputStream = null;
			PrintWriter printWriter =null;
			try {
				socket =new Socket("127.0.0.1",9999);
				outputStream = socket.getOutputStream();
				printWriter =new PrintWriter(outputStream);
				printWriter.write("123");
				System.out.println("123");
				printWriter.flush();
				Thread.sleep(10000);
				printWriter.write("345");
				System.out.println("345");
				printWriter.flush();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				try {
					socket.close();
					outputStream.close();
					printWriter.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		

	public static void main(String[] args) {
		ExecutorService executorService= null;
		executorService = Executors.newFixedThreadPool(5);
		for (int i = 0; i < 5; i++) {
			executorService.submit(new SocketClients());
		}
	}

}
